<template>
  <div class="sz-ui">
    <!-- 组件菜单 -->
    <section class="sz-ui__menu">
      <div class="title">组件总览</div>
      <div
        class="sz-ui__menu-item"
        v-for="route in menus"
        :class="curRoute && (route.path === curRoute.path) && 'active'"
        :key="route.name"
        @click="handleClick(route)"
      >
        <router-link :to="route.path">
          <div>{{ route.name }} {{ route.meta.title }}</div>
        </router-link>
      </div>
    </section>
    <!-- 组件详情 -->
    <section class="sz-ui__detail">
      <div class="header">{{ curRoute && curRoute.meta.title }}</div>
      <div class="container">
        <router-view></router-view>
      </div>
    </section>
  </div>
</template>

<script>
import { routes } from "@/router";
import Demo from "./demo/index.vue";

export default {
  components: { Demo },
  data() {
    return {
      curRoute: routes[1]
    };
  },
  computed: {
    menus() {
      return routes.filter((r) => r.path !== "/");
    }
  },
  watch: {
    '$route': {
      handler: function (to, from) {
        this.curRoute = this.menus.find(m => m.path === to.path);
      },
      immediate: true
    }
  },
  methods: {
    handleClick(item) {
      this.curRoute = item;
    }
  }
};
</script>

<style lang="scss" scoped>
$sz-active-color: #409eff;
.sz-ui {
  display: flex;
  height: 100vh;
  .title {
    font-size: 18px;
    color: #666;
    margin-bottom: 16px;
  }
  .active {
    color: $sz-active-color;
  }
  &__menu {
    padding: 24px;
    width: 200px;
    overflow-y: auto;
    box-shadow: 10px 0 10px -10px rgba(18, 21, 38, 0.3);
    z-index: 100;
    &-item {
      cursor: pointer;
      font-size: 14px;
      line-height: 32px;
      &:hover {
        color: $sz-active-color;
      }
    }
  }
  &__detail {
    flex: 1;
    overflow-y: auto;
    position: relative;
    .header {
      position: sticky;
      top: 0;
      left: 0;
      z-index: 99;
      padding: 24px 24px 12px 24px;
      background-color: #fff;
      font-size: 18px;
    }
    .container {
      padding: 12px 24px 24px 24px;
    }
  }
}
</style>
